import { Dimensions } from "react-native";

const { width, height } = Dimensions.get("screen");

// 初始化 vw 和 vh
export let vw = width / 100;
export let vh = height / 100;

// 更新屏幕尺寸函数
const updateDimensions = () => {
	const { width, height } = Dimensions.get("window");
	vw = width / 100;
	vh = height / 100;
};

// 添加事件监听
const dimensionChangeListener = Dimensions.addEventListener(
	"change",
	updateDimensions
);

// 清除监听器
export const removeDimensionListener = () => {
	if (dimensionChangeListener) {
		dimensionChangeListener.remove();
	}
};
